package tx.audioAndVideoRecorder;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;

import android.os.Environment;

public class MyAccessToFiles {
	
	private static final String AUDIO_RECORDER_FOLDER = "AudioRecorder";
	private static final String VIDEO_RECORDER_FOLDER = "VideoRecorder";
	private static ArrayList<String> mAudioFiles = null;
	private static String mRoodNodePath = null;
	
	public MyAccessToFiles() {
		
		mRoodNodePath = Environment.getExternalStorageDirectory().getPath();
		mAudioFiles = new ArrayList<String>();
		this.reloadAudioFiles();
	}

	
	public static void setAudioFiles(ArrayList<String> mAudioFiles) {
		MyAccessToFiles.mAudioFiles = mAudioFiles;
	}

	/*
	 * Be careful to use reloadAudioFiles before
	 * TODO : Maybe increase this function in adding reloadAudioFiles inside
	 * 
	 */
	public static ArrayList<String> getAudioFiles() {
		return mAudioFiles;
	}
	
	
	public String[] getAudioFilesStringArray() {
		
		String[] stringFile = null;
				
		if(mAudioFiles != null)
		{
			stringFile = new String[mAudioFiles.size()];
	        
	        for(int i=0; i< mAudioFiles.size();i++)
	        	stringFile[i] = mAudioFiles.get(i);
		}
		
		return stringFile;
	}
	
	public void reloadAudioFiles(){
		File fileTemp = new File(mRoodNodePath+"/"+AUDIO_RECORDER_FOLDER);
		ArrayList <File> audioFiles = new ArrayList <File>(Arrays.asList(fileTemp.listFiles()));
		
		//restart mAudioFiles
		mAudioFiles = null;
		mAudioFiles = new ArrayList<String>();
		
		for(File temp : audioFiles)
			mAudioFiles.add(temp.getAbsolutePath());
	}
	
	public void reloadVideoFiles(){
		//TODO
	}

}
